<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="../bootstrap-5.1.3-dist/css/bootstrap.css" rel="stylesheet">
    <script src="../bootstrap-5.1.3-dist/js/bootstrap.bundle.js"></script>
</head>
<style>
    .Scrollspy {
        width: 500px;
        /*定义宽度*/
        height: 300px;
        /*定义高度*/
        overflow: scroll;
        /*定义当内容溢出元素框时，浏览器显示滚动条以便查看其余的内容*/
    }
</style>

<body class="container">
    <h3 align="center">在导航栏中的滚动监听</h3>
    <nav id="navbar" class="navbar navbar-light bg-light">
        <ul class="nav nav-pills">
            <li class="nav-item">
                <a class="nav-link" href="#list1">首页</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#list2">热门蔬菜</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">热销水果</a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="#menu1">精品葡萄</a>
                    <a class="dropdown-item" href="#menu2">精品苹果</a>
                    <a class="dropdown-item" href="#menu3">精品香蕉</a>
                </div>
            </li>
        </ul>
    </nav>

    <div data-spy="scroll" data-target="#navbar" data-bs-offset="80" class="Scrollspy">
        <h4 id="list1">惠丰商城</h4>
        <p><img src="1.jpg" alt="" class="img-fluid"></p>
        <h4 id="list2">热门蔬菜</h4>
        <p><img src="2.jpg" alt="" class="img-fluid"></p>
        <h4 id="menu1">精品葡萄</h4>
        <p><img src="3.jpg" alt="" class="img-fluid"></p>
        <h4 id="menu2">精品苹果</h4>
        <p><img src="4.jpg" alt="" class="img-fluid"></p>
        <h4 id="menu3">精品香蕉</h4>
        <p><img src="5.jpg" alt="" class="img-fluid"></p>
    </div>

</body>

</html>